let webpack = require("webpack");
const path = require("path");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = ["js", "css", "woff", "ttf"];
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

function resolve (dir) {
    return path.join(__dirname, dir);
}

//let baseUrl = 'http://192.168.101.176:8010' 
// let baseUrl = 'http://192.168.43.243:8015' //服务器地址
// let baseUrl = 'http://192.168.101.23:8010' //服务器地址
let baseUrl = 'http://192.168.198.175:8015' //服务器地址
    // let baseUrl = 'http://172.20.10.5:8015' //服务器地址
// let baseUrl = 'http://localhost:8010' //服务器地址
// let baseUrl = 'http://192.168.43.18:8010' //服务器地址



module.exports = {
    lintOnSave: false,
    productionSourceMap: false,
    parallel: true,
    publicPath: '/platform/',
    devServer: {
        proxy: {
            "/api": {
                target: baseUrl,
                pathRewrite: {
                    "^/api": "/api"
                }
            },
            "/admin": {
                target: baseUrl,
                pathRewrite: {
                    "^/admin": "/"
                }
            },
            "/gen": {
                target: baseUrl,
                pathRewrite: {
                    "^/gen": "/"
                }
            },
            "/auth": {
                target: baseUrl,
                pathRewrite: {
                    "^/auth": "/auth"
                }
            },
            "/mzzx-api": {
                target: "http://mzj.sz.gov.cn/",
                pathRewrite: {
                    "^/mzzx-api": "/"
                }
            },
            "/rent": {
                target: baseUrl,
                pathRewrite: {
                    "^/rent": "/rent"
                }
            },
            "/assess": {
                target: baseUrl,
                pathRewrite: {
                    "^/assess": "/assess"
                }
            }
        },
        overlay: {
            warnings: true,
            errors: true
        },
        port: 8091,
        https: false,
        open: true
    },
    chainWebpack: config => {
        config.plugins.delete("prefetch");
        config.resolve.alias
            .set("~", resolve("src"))
            .set("assets", resolve("src/assets"));
    },
    configureWebpack: {
        plugins: [
            // 代码size分析
            //new BundleAnalyzerPlugin(),
            // 去除moment的s其他语言包
            new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /ja|it/),

            new webpack.ProvidePlugin({
                blp: [
                    resolve("./src/assets/js/business-logic-processing.js"),
                    "default"
                ],
                utils: [resolve("./src/utils/index.js"), "default"]
            }),
            
            new CompressionWebpackPlugin({
                algorithm: "gzip",
                test: new RegExp(
                    "\\.(" + productionGzipExtensions.join("|") + ")$"
                ),
                threshold: 10240,
                minRatio: 0.8
            })
        ]
    },
    css: {
        loaderOptions: {
            scss: {
                prependData: `
                    @import "@/assets/style/common.scss";
                    @import "@/assets/style/public.scss";
                `
            }
        }
    },
};
